
package com.jf.cloud.multishop.controller;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.multishop.dto.ShopPaymentBalanceDTO;
import com.jf.cloud.multishop.model.ShopPaymentBalance;
import com.jf.cloud.multishop.service.ShopPaymentBalanceService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 商家余额支付表
 *
 * @author zz
 * @date 2022-06-22 17:09:12
 */
@RestController("multishopShopPaymentBalanceController")
@RequestMapping("/m/shop_payment_balance")
@Tag(name = "商家余额支付表")
public class ShopPaymentBalanceController {

    @Autowired
    private ShopPaymentBalanceService shopPaymentBalanceService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取商家余额支付表列表" , description = "分页获取商家余额支付表列表")
    public ServerResponseEntity<PageVO<ShopPaymentBalance>> page(@Valid PageDTO pageDTO) {
        PageVO<ShopPaymentBalance> shopPaymentBalancePage = shopPaymentBalanceService.page(pageDTO);
        return ServerResponseEntity.success(shopPaymentBalancePage);
    }

    @GetMapping
    @Operation(summary = "获取商家余额支付表" , description = "根据balancePaymentId获取商家余额支付表")
    public ServerResponseEntity<ShopPaymentBalance> getByBalancePaymentId(@ParameterObject @RequestParam Long balancePaymentId) {
        return ServerResponseEntity.success(shopPaymentBalanceService.getByBalancePaymentId(balancePaymentId));
    }

    @PostMapping
    @Operation(summary = "保存商家余额支付表" , description = "保存商家余额支付表")
    public ServerResponseEntity<Void> save(@Valid @RequestBody ShopPaymentBalanceDTO shopPaymentBalanceDTO) {
        ShopPaymentBalance shopPaymentBalance = mapperFacade.map(shopPaymentBalanceDTO, ShopPaymentBalance.class);
        shopPaymentBalance.setBalancePaymentId(null);
        shopPaymentBalanceService.save(shopPaymentBalance);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新商家余额支付表" , description = "更新商家余额支付表")
    public ServerResponseEntity<Void> update(@Valid @RequestBody ShopPaymentBalanceDTO shopPaymentBalanceDTO) {
        ShopPaymentBalance shopPaymentBalance = mapperFacade.map(shopPaymentBalanceDTO, ShopPaymentBalance.class);
        shopPaymentBalanceService.update(shopPaymentBalance);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除商家余额支付表" , description = "根据商家余额支付表id删除商家余额支付表")
    public ServerResponseEntity<Void> delete(@RequestParam Long balancePaymentId) {
        shopPaymentBalanceService.deleteById(balancePaymentId);
        return ServerResponseEntity.success();
    }
}
